<%--
  Created by IntelliJ IDEA.
  User: 10452
  Date: 2022/3/24
  Time: 14:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="/welcome/Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="/welcome/Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="/welcome/Css/style.css" />
    <script type="text/javascript" src="/welcome/Js/jquery.js"></script>
    <script type="text/javascript" src="/welcome/Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="/welcome/Js/bootstrap.js"></script>
    <script type="text/javascript" src="/welcome/Js/ckform.js"></script>
    <script type="text/javascript" src="/welcome/Js/common.js"></script>

</head>
<body>
<form class="form-inline definewidth m20" action="" method="get" id="passform">
    <table>
        <tr>
            <td align="right">原密码:</td><td><input type="password" id="oldpass" name="oldpass" onblur="validateOldPass()"/></td>
        </tr>
        <tr>
            <td align="right">新密码:</td><td><input type="password" id="newpass" name="newpass" onblur="validateNewPass()"/></td>
        </tr>
        <tr>
            <td align="right">确认密码:</td><td><input type="password" id="confirmpass" name="confirmpass" onblur="validateConfirmPass()"/></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><br/>
                <input id="savepass" type="button" value="保存" class="btn btn-primary"/>
            </td>
        </tr>
    </table>
</form>
</body>

<script type="text/javascript">
    $(function () {
        var password = ${sessionScope.user.u_passWord}
        $("#savepass").click(function () {
            if (validateOldPass()&&validateNewPass()&&validateConfirmPass()){
                var oldpass = $("#oldpass").val()
                var newpass = $("#newpass").val()
                var confirmpass = $("#confirmpass").val()
                if (password != oldpass){
                    alert("原密码输入有误");
                    return;
                }
                if (newpass != confirmpass){
                    alert("两次密码输入有误")
                    return;
                }
                $.ajax({
                    type: "POST",
                    url: "/user/pass",
                    data: $("#passform").serialize()+"&_method=PUT",
                    dataType:"json",
                    success: function(vo){
                        if (vo.code == 200){
                            alert(vo.msg)
                        }else{
                            alert(vo.msg)
                        }
                    }
                })
            }
        } )

    })


    function validateOldPass() {
        var oldpass = $("#oldpass").val()
        if (oldpass == ""){
            alert("原密码不能为空")
            return false;
        }
        return true;
    }
    function validateNewPass() {
        var newpass = $("#newpass").val()
        var regex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,15}');
        if (newpass == ""){
            alert("新密码不能为空")
            return false;
        }
        if (!regex.test(newpass)){
            alert("密码中必须包含字母、数字、特称字符，至少8个字符，最多15个字符")
            return false;
        }
        return true;
    }
    function validateConfirmPass() {
        var confirmpass = $("#confirmpass").val()
        var regex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,15}');
        if (confirmpass == ""){
            alert("请确认新密码")
            return false;
        }
        if (!regex.test(confirmpass)){
            alert("密码中必须包含字母、数字、特称字符，至少8个字符，最多15个字符")
            return false;
        }
        return true;
    }
</script>
</html>